<?php 

defined('_JEXEC') or die;

// pipapai 开发查看新用户流程在企业中心URL后增加 ？dev_showintro=1 的参数即可
$devbootstro = JRequest::getInt("dev_showintro",0);
$showbootstro = ((!empty($_['first_register'])) || $devbootstro==1) ? true : false; 

// disable core styles to avoid bs conflict 
OC_Util::$core_styles = array();

if(isDevMode()) {
   OCP\Util::addStyle('company', 'company');
   OCP\Util::addStyle('calendar', 'calendar.common');
   if($showbootstro) {
      OCP\Util::addStyle('themes/jobs/core/bs', 'bootstro');
      OCP\Util::addScript('themes/jobs/core/bs', 'bootstro');
   }
   OCP\Util::addScript('company', 'home');
   OCP\Util::addScript('company', 'autoactions');
} else {
   OCP\Util::addStyle('static', 'company');
   if($showbootstro) {
      OCP\Util::addStyle('static', 'bstro');
      OCP\Util::addScript('static', 'bootstro.min');
   }
   OCP\Util::addScript('static', 'apps/company.home.min'); 
   OCP\Util::addScript('static', 'apps/company.autoactions.min');
}


OCP\App::setActiveNavigationEntry('company_index');

$lang = PFactory::getLanguage();
$lang->load("com_jobs", JPATH_SITE, "zh-CN");

$user = $_['user'];
$iknow_free = JRequest::getString('iknow_free', null, 'cookie');

$userQuota = PCompanyHelper::getUserQuota();
$thirdaccounts_info = $_['thirdaccounts_info'];
$totalresumes = $_['totalresumes'];
$totalinterview = $_['totalinterview'];
$thirdaccounts_status = $_['thirdaccounts_status'];
$thirdaccount_51job = empty($thirdaccounts_info['51job']) ? null : $thirdaccounts_info['51job'];
$thirdaccount_zhilian = empty($thirdaccounts_info['zhilian']) ? null : $thirdaccounts_info['zhilian'];
$thirdaccount_lagou = empty($thirdaccounts_info['lagou']) ? null : $thirdaccounts_info['lagou'];
$thirdaccount_jiancai = empty($thirdaccounts_info['jiancai']) ? null : $thirdaccounts_info['jiancai'];
$thirdaccount_status_51job = empty($thirdaccounts_status['51job']['fetchjobs']) ? null : $thirdaccounts_status['51job']['fetchjobs'];
$thirdaccount_status_zhilian = empty($thirdaccounts_status['zhilian']['fetchjobs']) ? null : $thirdaccounts_status['zhilian']['fetchjobs'];
$thirdaccount_status_lagou = empty($thirdaccounts_status['lagou']['fetchjobs']) ? null : $thirdaccounts_status['lagou']['fetchjobs'];
$thirdaccount_status_jiancai = empty($thirdaccounts_status['jiancai']['fetchjobs']) ? null : $thirdaccounts_status['jiancai']['fetchjobs'];

$autofetchjobsinfo51job = !isset($thirdaccounts_status['51job']['autofetchjobs']) ? null : $thirdaccounts_status['51job']['autofetchjobs'];
$autofetchjobsinfozhilian = !isset($thirdaccounts_status['zhilian']['autofetchjobs']) ? null : $thirdaccounts_status['zhilian']['autofetchjobs'];
$autofetchjobsinfolagou = !isset($thirdaccounts_status['lagou']['autofetchjobs']) ? null : $thirdaccounts_status['lagou']['autofetchjobs'];
$autofetchjobsinfojiancai = !isset($thirdaccounts_status['jiancai']['autofetchjobs']) ? null : $thirdaccounts_status['jiancai']['autofetchjobs'];

$autofetchjobs_on_51job = ($autofetchjobsinfo51job === null || (isset($autofetchjobsinfo51job['disabled']) && $autofetchjobsinfo51job['disabled'] == 1))? 0 : 1;
$autofetchjobs_on_zhilian = ($autofetchjobsinfozhilian === null || (isset($autofetchjobsinfozhilian['disabled']) && $autofetchjobsinfozhilian['disabled'] == 1) || (isset($autofetchjobsinfozhilian['result']) && $autofetchjobsinfozhilian['result'] == 'captcha'))? 0 : 1;
$autofetchjobs_on_lagou = ($autofetchjobsinfolagou === null || (isset($autofetchjobsinfolagou['disabled']) && $autofetchjobsinfolagou['disabled'] == 1) || (isset($autofetchjobsinfolagou['result']) && $autofetchjobsinfolagou['result'] == 'captcha'))? 0 : 1;
$autofetchjobs_on_jiancai = ($autofetchjobsinfojiancai === null || (isset($autofetchjobsinfojiancai['disabled']) && $autofetchjobsinfojiancai['disabled'] == 1))? 0 : 1;

$quotaEnabled = PCompanyHelper::checkQuotaEnable(); 
?>
<script type="text/javascript" src="<?php print_unescaped(OC_Helper::linkTo('company/js', 'company.php'));?>"></script>

<div class="hr_companycenter_set" id="companycenter">

   <div class="hr_companycenter_top clearfix">
      <div class="hr_complogo pull-left"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><?php echo JobHelper::getUserAvatar($user,false); ?></td></tr></table></div>
      <div class="hr_companycenter_name pull-left">
         <h4 class="large">您好，<?=trim($user->comp_name)?>
            <?php if($user->validated == EMPLOYER_VALIDATED): ?>
            <i class="bstro_approve is_approve"></i>
            <?php else: ?>
            <a href="<?php echo OC_Helper::linkToRoute("company_license"); ?>" style="margin-right:0px;"><i class="bstro_approve not_approve"></i></a>
            <?php endif; ?>
         </h4>
         <div class="medium">
            <span class="gray">账户级别：<?=(isset($userQuota['title']) ? $userQuota['title'] : '免费用户')?></span>
            <a href="<?=OCP\Util::linkToRoute('jobpos_index',array('jobdir'=>'all'))?>">职位（<?=$_['stats']['jobs']['totaljobs']?>）</a>
            <?php if(!$quotaEnabled):?>
            <a href="<?=OCP\Util::linkToRoute('resumes_index')?>">简历（<?=$_['stats']['resumes']['totalresumes']?>）</a>

            <?php else:?>
            <a href="<?=OCP\Util::linkToRoute('resumes_index')?>">简历（<?=$_['stats']['resumes']['totalresumes']?> / <?=($userQuota['quota']['resume_max'] == 'any' ? '不限' : $userQuota['quota']['resume_max'])?>）</a>
            <?php if($_['masteruser'] && $userQuota['quota']['resume_max'] != 'any'): ?>
            <?php 
            $upgradeTips = '';
            if ($_['stats']['resumes']['totalresumes'] >= 0.9*$userQuota['quota']['resume_max'] && $_['stats']['resumes']['totalresumes'] < $userQuota['quota']['resume_max']) {
               $upgradeTips = '您的简历数已达90%上限，请及时升级账号。';
            } elseif ($_['stats']['resumes']['totalresumes'] >= $userQuota['quota']['resume_max']) {
               $upgradeTips = '您的简历数已达' . $userQuota['quota']['resume_max'] . '份上限，请及时升级账号。';
            }
            ?>
               <?php if (!empty($upgradeTips)): ?>
               <span class="yellow"><?=$upgradeTips?><a href="<?=OC_Helper::linkToRoute('company_quota')?>">立即升级</a></span>
               <?php endif; ?>
            <?php endif; ?>
            <?php endif; ?>
         </div>
      </div>

      <?php PCompanyHelper::showValidateStatus($user); ?>
   
   </div>
   
   <div class="hr_companycenter_wrapper">
      <div class="hr_netaddress">
         <span>公 司 主 页：</span>
         <a id="homelink" target='_blank' href="<?=PCompanyHelper::getHomeLink()?>"><?=PCompanyHelper::getHomeLink()?></a>
         <?php if(!$_['isset_subdomain']): ?>
         <a class="set_pdomain medium <?=($user->validated != EMPLOYER_VALIDATED ? 'notvalidated':'')?>" href="<?php echo $user->validated != EMPLOYER_VALIDATED ? OC_Helper::linkToRoute('company_license'):'javascript:;'?>">设置专属域名</a>
        
         <div class="hr_net_tipdialog popup hr_setdomain" id="hr_setdomain" style="width:320px; display:none; top:auto; left:auto; z-index:1;">
            <div class="hr_net_point"></div>
            <form id="setdomainform" action="<?php echo OC_Helper::linkToRoute("company_setsubdomain"); ?>" method="post" name="basicform">
         	<div class="hr_net_tipcontent medium">
         	   <div class="domaintxttip">域名长度3~64位，设置过后不可更改</div>
         	   <div class="domaininput">专属域名：http:// <input type="text" name="sub_domain" id="sub_domain" class="input-small"/> .pipahr.com</div>
         	   <div class="domainbtn"><label class="error" generated="true" for="sub_domain" style="display:none;">域名长度为5～64位</label><input class="ppp_bluebtn medium" type="submit" value="确认"/><a class='closediv' href="javascript:;">取消</a></div>
            </div>
            <input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
            </form>
         </div>      
        <?php endif; ?>
      </div>

      
      <div class="company_twolevel clearfix">
         <?php if($_['masteruser']): ?>
         <div class="hr_netaddress hr_widgetsbox pull-left" style="margin-bottom:0px; width:53%;">
            <div class="hr_widgetstitle clearfix">
               <span><b>同步信息</b></span>
               <div class="configemail_self pull-right medium">同步职位或手动配置转发邮箱 <span><?php echo $_['resumeforward']['email']?></span> 接收简历 <a class="howtoaccept medium" href="javascript:;">如何配置？</a></div>
            </div>
            <div class="hr_widgetscontent clearfix">
               <div class="synchronous_info synchronous_info_new">
                  <div><i class="config_51"></i>&nbsp;前程无忧</div>
                  <?php if(empty($thirdaccount_status_51job) || $thirdaccount_status_51job['result'] != 'syncing'): ?>
                  <?php 
                     list($sync_51job_title, $sync_51job_iclass) = PCompanyHelper::getSyncStatus('fetchjobs', $thirdaccount_status_51job);
                  ?>
                  <i title="<?=$sync_51job_iclass ? $sync_51job_title : '尚未同步'?>" class="<?=$sync_51job_iclass?>"></i>
                  <a href="#accountsetdialog_51job" class="ppp_bluebtn" id="sync_click_51job" data-syncaction='fetchjobs' data-autofetchon="<?=$autofetchjobs_on_51job ?>" data-vid="<?=$user->vid ?>" data-type="51job" title="<?=$sync_51job_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>
            
               <div class="synchronous_info synchronous_info_new" style="margin-left:15px;">
                  <div><i class="config_zhilian"></i>&nbsp;智联招聘</div>
                  <?php if(empty($thirdaccount_status_zhilian) || $thirdaccount_status_zhilian['result'] != 'syncing'): ?>
                  <?php
                     list($sync_zhilian_title, $sync_zhilian_iclass) = PCompanyHelper::getSyncStatus('fetchjobs', $thirdaccount_status_zhilian);
                  ?>
                  <i title="<?=$sync_zhilian_iclass ? $sync_zhilian_title : '尚未同步'?>" class="<?=$sync_zhilian_iclass?>"></i>
                  <a href="#accountsetdialog_zhilian" class="ppp_bluebtn" id="sync_click_zhilian" data-type="zhilian" data-syncaction='fetchjobs' data-autofetchon="<?=$autofetchjobs_on_zhilian ?>" data-vid="<?=$user->vid ?>"  title="<?=$sync_zhilian_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>

               <div class="synchronous_info synchronous_info_new" style="margin-left:15px;">
                  <div><i class="config_lagou"></i>&nbsp;拉勾</div>
                  <?php if(empty($thirdaccount_status_lagou) || $thirdaccount_status_lagou['result'] != 'syncing'): ?>
                  <?php
                     list($sync_lagou_title, $sync_lagou_iclass) = PCompanyHelper::getSyncStatus('fetchjobs', $thirdaccount_status_lagou);
                  ?>
                  <i title="<?=$sync_lagou_iclass ? $sync_lagou_title : '尚未同步'?>" class="<?=$sync_lagou_iclass?>"></i>
                  <a href="#accountsetdialog_lagou" class="ppp_bluebtn" id="sync_click_lagou" data-type="lagou" data-syncaction='fetchjobs' data-autofetchon="<?=$autofetchjobs_on_lagou ?>" data-vid="<?=$user->vid ?>"  title="<?=$sync_lagou_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>
               
               <div class="synchronous_info synchronous_info_new" style="margin-left:15px;">
                  <div><i class="config_jianzhu"></i>&nbsp;建筑英才</div>
                  <?php if(empty($thirdaccount_status_jiancai) || $thirdaccount_status_jiancai['result'] != 'syncing'): ?>
                  <?php
                     list($sync_jiancai_title, $sync_jiancai_iclass) = PCompanyHelper::getSyncStatus('fetchjobs', $thirdaccount_status_jiancai);
                  ?>
                  <i title="<?=$sync_jiancai_iclass ? $sync_jiancai_title : '尚未同步'?>" class="<?=$sync_jiancai_iclass?>"></i>
                  <a href="#accountsetdialog_jiancai" class="ppp_bluebtn" id="sync_click_jiancai" data-syncaction='fetchjobs' data-autofetchon="<?=$autofetchjobs_on_jiancai ?>" data-vid="<?=$user->vid ?>" data-type="jiancai" title="<?=$sync_jiancai_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>
               
            </div>
         </div>
         <?php endif; ?>
         
         <div class="hr_widgetsbox hr_dongtaishow pull-right" style="width:46%;">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
               <tr>
                  <th>动态</th>
                  <th>最近1个月</th>
                  <th>最近7天</th>
                  <th>最近3天</th>
               </tr>
               <?php if($totalresumes['1m']>0 || $totalresumes['1w']>0 || $totalresumes['3d']>0): ?>
               <tr>
                  <td>简历</td>
                  <td><span><?php echo $totalresumes['1m']?$totalresumes['1m']:0; ?></span></td>
                  <td><span><?php echo $totalresumes['1w']?$totalresumes['1w']:0; ?></span></td>
                  <td><span><?php echo $totalresumes['3d']?$totalresumes['3d']:0; ?></span></td>
               </tr>
               <?php else: ?>
               <tr>
                  <td>简历</td>
                  <td colspan="4" class="nodatatd yahei">暂无信息，请您先 <a href="<?php echo OC_Helper::linkToRoute("company_synchronousinfo")?>">同步职位</a> 或 <a href="<?php echo OC_Helper::linkToRoute("resume_showaddform")?>">创建简历</a></td>
               </tr>
               <?php endif; ?>
               <?php if($totalinterview['1m']>0 || $totalinterview['1w']>0 || $totalinterview['3d']>0): ?>
               <tr class="lasttr">
                  <td>面试</td>
                  <td><span><?php echo $totalinterview['1m']?$totalinterview['1m']:0; ?></span></td>
                  <td><span><?php echo $totalinterview['1w']?$totalinterview['1w']:0; ?></span></td>
                  <td><span><?php echo $totalinterview['3d']?$totalinterview['3d']:0; ?></span></td>
               </tr>
               <?php else: ?>
               <tr class="lasttr">
                  <td>面试</td>
                  <td colspan="4" class="nodatatd yahei">暂无信息，请您先 <a id="setinterview" style="margin-left:0px;" href="<?php echo OC_Helper::linkToRoute("calendar_home").'?adddialog=1'; ?>">安排面试</a></td>
               </tr>
               <?php endif; ?>
               
            </table>
         </div>
      </div>
   </div>
   
   <?php if($_['stats']['jobs']['totaljobs'] <= 0 || $devbootstro==1): ?>
   
   <div class="hr_companycenter_wrapper <?php echo $showbootstro ? "first_register" : '';?>" data-vid="<?=$user->vid?>" id="showbootstro_cpy">   
      <div class="hr_cloudintro yahei">云招聘使用流程：</div>
      <div class="hr_cloudintrodetail">枇杷派云招聘是基于云计算的招聘管理工具，为企业提高招聘效率，节约人力成本，规范招聘流程，提升企业形象。</div>
      <div class="hr_companystep">
         <div class="hr_c_1 hr_c_m">
            <a href="<?php echo OC_Helper::linkToRoute("company_license"); ?>" target="_blank"></a>
            <span><a href="<?php echo OC_Helper::linkToRoute("company_license"); ?>" target="_blank">上传营业执照</a>，通过验证即可使用云招聘所有功能</span>
         </div>
         <div class="hr_c_2 hr_c_m">
            <a></a>
            <span>与第三方招聘网站信息同步，点击<a href="<?php echo OC_Helper::linkToRoute("company_synchronousinfo"); ?>" target="_blank">同步职位</a>开始同步，在顶部“通知”中查看同步进度</span>
         </div>
         <div class="hr_c_3 hr_c_m">
            <a href="<?php echo OC_Helper::linkToRoute("jobpos_home"); ?>" target="_blank"></a>
            <span>同步完成后，可管理职位，设置匹配条件及评测，精确匹配人才</span>
         </div>
         <div class="hr_c_4 hr_c_m">
            <a href="<?php echo OC_Helper::linkToRoute("calendar_home"); ?>" target="_blank"></a>
            <span>安排面试，日程短信及邮件提醒，方便人才跟踪管理</span>
         </div>
         <div class="hr_c_5 hr_c_m">
            <a href="<?php echo OC_Helper::linkToRoute("company_subaccounts"); ?>" target="_blank"></a>
            <span>多个子账号协同管理，<a href="<?php echo OC_Helper::linkToRoute("company_subaccounts"); ?>" target="_blank">立即创建</a><br/>指定职位，自定义权限</span>
         </div>
         <div class="hr_c_6 hr_c_m">
            <a href="<?=JURI::base()?>helps/doc/product/whatcloudforyou.html" class="yahei large">更多功能，点击查看</a>
         </div>
      </div>
   </div>
   
   <?php else: ?>

   <div class="hr_companycenter_resumeshow clearfix" id="summarylist">
      <img src="/images/3/blue-loading.gif">
   </div>
   <?php endif; ?>

</div>

<div class="hr_net_tipdialog popup" id="hr_howtoconfig" style="width:260px; display:none; top:auto; left:auto;">
   <div class="hr_net_point"></div>
   <div class="closediv"></div>
	<div class="hr_net_tipcontent">
	   <p>1. 登录<a href="http://ehire.51job.com/MainLogin.aspx" target="_blank">前程无忧</a> / <a href="http://hr.zhaopin.com/hrclub/index.html" target="_blank">智联招聘</a> / <a href="http://ent.buildhr.com/login" target="_blank">建筑英才</a></p>
      <p>2. 进入已发布的职位详情页</p>
      <p class="clearfix"><em class="pull-left">3.</em> <em class="blockstyle">找到<b>简历接收方式</b>，填写云招聘邮箱<br/>地址 <b class="yellowcolor"><?php echo $_['resumeforward']['email']?></b></em></p>
      <p class="textright"><a target="_blank" href="<?=JURI::base()?>helps/doc/product/resumeforward_51job.html">查看详细帮助</a></p>
   </div>
</div>

<!-- Modal 51job -->
<div id="accountsetdialog_51job" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal zhilian -->
<div id="accountsetdialog_zhilian" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal lagou -->
<div id="accountsetdialog_lagou" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal jiancai -->
<div id="accountsetdialog_jiancai" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>


<!-- 企业中心自动同步确认dialog -->
<div class="modal hide fade autorenew_dialog" id="autofetchjobs">
</div>
<div class="modal hide fade autorenew_dialog" id="autofetchjobs_successdialog">  
</div>

<div id="dialog_holder"></div>
<div id="modal_holder" class="modal hide interviewtime_dialog" style="position:absolute;"></div>
<div id="preview_holder" class="modal changeinterview_dialog popup" style="display:none; max-width:500px; position:absolute; z-index:100;"></div>
